package per.srp.demo.carLink.testP;

import per.srp.demo.carLink.Utils.CarInfoCodeTool;
import per.srp.demo.carLink.Utils.SocketOperation;

import java.net.Socket;

public class Tool {
    public static void sendOnce(String ip,int port,String json) throws Exception {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    String encodeJson = CarInfoCodeTool.enCodeString(json);

                    Socket client = new Socket(ip,port);


                    SocketOperation.writeAndClose(client,encodeJson);
                    String readStr = SocketOperation.read(client);

                    System.out.println(readStr+"\n"+CarInfoCodeTool.deCodeString(readStr));


                    client.close();
                    System.out.println("over");
                }catch(Exception e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();
    }
}
